/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.comm.mavlink;

import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author amalikov
 */
public class ProtocolDebugAdapter {
	public ProtocolDebugAdapter(Protocol p, byte[] filteredId) {
		this.p = p;
		filter = new HashSet<>();
		for (byte id : filteredId)
			filter.add(id);
	}
	
	public Message recv() {
		Message msg = p.recv();
		print("recv", msg);
		return msg;
	}
	
	public void send(Message msg) {
		print("send", msg);
		p.send(msg);
	}
	
	private void print(String prefix, Message msg) {
		if (msg != null && !filter.contains(msg.msgId))
			System.out.println(prefix + " " + msg);
	}
	
	private final Protocol p;
	private final Set<Byte> filter;
}
